package gui;

import gui.abstracts.TelasPMPE;

import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;

import util.AtualizarRelogio;
import java.awt.Dimension;
import java.awt.Font;

public class PanelPonto extends TelasPMPE{

	/**
	 * 
	 */
	private static final long serialVersionUID = -1320676798792550517L;
	static PanelPonto panelPonto = null;
	JPasswordField fldSenha = null;
	JLabel horas = null;
	JLabel data = null;
	JLabel lblData = null;
	JLabel lblHoras = null;
	JLabel lblSenha = null;
	JButton botao = null;
	
	private PanelPonto() {
		super();
		this.setLayout(null);
		this.setarPreferredSize();
		this.startup();
	
	}
	
	static PanelPonto getPanelPonto(){
		if (panelPonto == null){
			panelPonto = new PanelPonto();
		}
		panelPonto.clearFields();
		return panelPonto;
	}
	
	public void clearFields() {
		this.getPasswordField().setText("");	
	}

	private void startup() {
		add(getPasswordField());
		add(getButtonPonto());
		add(getLblSenha());
		add(getLblData());
		add(getData());
		add(getLblHora());
		add(getHoras());
		new Thread(new AtualizarRelogio(getHoras())).start();		
	}
	
	private JLabel getHoras() {
		if(horas == null){
			horas = new JLabel("HH:MM:SS");
			horas.setFont(new Font("Tahoma", Font.BOLD, 21));
			horas.setBounds(82, 52, 155, 49);
		}
		return horas;
	}
	private JLabel getLblHora() {
		if(lblHoras == null){
			lblHoras = new JLabel("Hora :");
			lblHoras.setFont(new Font("Tahoma", Font.BOLD, 14));
			lblHoras.setBounds(24, 71, 46, 14);
		}
		return lblHoras;
	}
	private JLabel getData() {
		if(data == null){
			data = new JLabel("DD/MM/AAAA");
			data.setFont(new Font("Tahoma", Font.BOLD, 21));
			data.setBounds(70, 11, 157, 49);
		}
		return data;
	}
	private JLabel getLblData() {
		if(lblData == null){
			lblData = new JLabel("Data :");
			lblData.setFont(new Font("Tahoma", Font.BOLD, 14));
			lblData.setBounds(12, 30, 46, 14);
		}
		return lblData;
	}
	private JLabel getLblSenha() {
		if(lblSenha == null){
			lblSenha = new JLabel("senha :");
			lblSenha.setBounds(36, 138, 46, 14);
		}
		return lblSenha;

	}
	private JButton getButtonPonto() {
		if(botao == null){
			botao = new JButton("Registrar Ponto");
			botao.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					registrarPonto();
				}
			});
			botao.setBounds(54, 180, 138, 23);
		}
		return botao;
	}
	protected void registrarPonto() {
	
//		String login = TelaInicial.getTelaInicial().getLogin();
//		if(Fachada.getFachada.existeUsuario(login,getPasswordField().getPassword())){
//			Data dataAtual = new Data(data.getText(),horas.getText());
//			Fachada.getFachada.registrarPonto(login,dataAtual);
//		}
//		else{
//			JOptionPane.showMessageDialog(this,"Senha incorreta");
//		}
	
	}
	private JPasswordField getPasswordField() {
		if(fldSenha == null){
		fldSenha = new JPasswordField();
		fldSenha.setBounds(82, 135, 121, 20);
		}
		return fldSenha;
	}
	@Override
	public
	String getTitle() {
		return "PontoPMPE - Registrar Ponto";
	}
	@Override
	public void setarPreferredSize() {
		
		this.setPreferredSize(new Dimension(247, 225));			
	}
}
